package {{onceData.templateInfo.otherInfo.controllerPackage}};


import com.zimug.commons.exception.AjaxResponse;
import {{onceData.templateInfo.otherInfo.mybatisPackage}}.model.{{capitalizeCamelTableName}};
import {{onceData.templateInfo.otherInfo.servicePackage}}.{{capitalizeCamelTableName}}Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统数据字典配置控制层代码
 * @author 字母哥
 */
@RestController
@RequestMapping("/{{flatTableName}}")
public class {{capitalizeCamelTableName}}Controller {

  @Resource
  private {{capitalizeCamelTableName}}Service {{camelTableName}}Service;

  /**
   * 查询所有
   * @return List<{{capitalizeCamelTableName}}> 所有数据字典项
   */
  @PostMapping(value = "/all")
  public List<{{capitalizeCamelTableName}}> all() {
    return {{camelTableName}}Service.all();
  }

  /**
   * 根据查询参数参训数据字典
{% for field in queryParamFields %}
   * @param {{field.columnName}} {{field.columnComment}}
{% endfor %}
   * @return 数据字典项列表
   */
  @PostMapping(value = "/query")
  public List<{{capitalizeCamelTableName}}> query(
{% for field in queryParamFields %}
{% if loop.last%}
           @RequestParam("{{field.columnName}}") {{field.columnJavaType | split('.') | last}} {{field.columnName}}  ) {
{% elif not loop.last %}
           @RequestParam("{{field.columnName}}") {{field.columnJavaType | split('.') | last}} {{field.columnName}},
{% endif %}
{% endfor %}
    return {{camelTableName}}Service.query(
{% for field in queryParamFields %}
{% if loop.last%}
            {{field.columnName}} );
{% elif not loop.last %}
            {{field.columnName}},
{% endif %}
{% endfor %}
  }

  /**
   * 根据id更新数据数据字典项目
   * @param {{camelTableName}} 更新实体（必须包含id）
   * @return 更新成功结果
   */
  @PostMapping(value = "/update")
  public AjaxResponse update(@RequestBody {{capitalizeCamelTableName}} {{camelTableName}}) {
    {{camelTableName}}Service.update({{camelTableName}});
    return AjaxResponse.success("更新数据字典项成功！");
  }

  /**
   * 新增数据字典项
   * @param {{camelTableName}} 新增实体
   * @return 更新成功结果
   */
  @PostMapping(value = "/add")
  public AjaxResponse add(@RequestBody {{capitalizeCamelTableName}} {{camelTableName}}) {
    {{camelTableName}}Service.add({{camelTableName}});
    return AjaxResponse.success("新增数据字典项成功！");
  }

  /**
   * 根据id删除数据字典项
   * @param id 删除项id
   * @return 删除成功结果
   */
  @PostMapping(value = "/delete")
  public AjaxResponse delete(@RequestParam Long id) {
    {{camelTableName}}Service.delete(id);
    return AjaxResponse.success("删除数据字典项成功!");
  }

}
